package main.java.com.blog.test;

import com.alibaba.fastjson.JSON;
import com.blog.entity.*;
import com.blog.service.*;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Admin on 2017/6/1.
 */
@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = {"classpath:spring-config.xml", "classpath:spring-mybatis.xml"})
public class test {

    private static final Logger LOGGER = Logger.getLogger(UserService.class);

    @Autowired
    private UserService userService;

    @Autowired
    private InfoService infoService;


    @Autowired
    private ArtService artService;

    @Autowired
    private FabService fabService;

    @Autowired
    private ForwordService forwordService;

    @Test
    public void test() {

        //User user =userService.findByAccount("lyh");
        User user = userService.findById(1);
        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(user));
        System.out.println(JSON.toJSON(user));
    }

    @Test
    public void test2() {
        User user = userService.findByAccount("lyh");
        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(user));

    }

    @Test
    public void test3() {
        List<User> list = new ArrayList<>();
        list = userService.findAll();
//        Map<Integer,User> map = userService.findAll();

        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(list));
        System.out.println(JSON.toJSON(list));

    }

    @Test
    public void testupdate() {
        Info info = new Info();
        info.setInfoName("lyh");
        info.setInfoSex("男");
        info.setInfoTime("2017/06/06");
        info.setInfoHome("四川省");
        info.setInfoCulture("本科");
        infoService.addInfo(info);
    }

    @Test
    public void testupdate1() {
        Info info = infoService.findByName("lyh");
        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(info));
    }

    @Test
    public void testupdate2() {
        Info info = new Info();
        info.setInfoName("lyh");
        info.setInfoSex("男");
        info.setInfoTime("2017/07/07");
        info.setInfoHome("四川省南充市");
        info.setInfoCulture("本二科");
        infoService.updateInfo(info);
    }


    @Test
    public void testDelete() {
        Art art = new Art();
        art.setArtTitle("我的博客");
        art.setArtContext("我的第一篇博客");
        art.setUserAccount("lyh");
        artService.addArt(art);
    }

    @Test
    public void testDelete1() {

        int i = artService.deleteByTitle("我的博客");
        System.out.println(i);
    }

    @Test
    public void testselect() {

        Art art = artService.findByTitle("我的博客");
        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(art));
    }

    @Test
    public void testSelectAll() {

        List<Art> artList = artService.findByAll();
        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(artList));
    }

    @Test
    public void testSeletByAccount() {
        List<Art> artList = artService.findByArtAccount("lyh");

        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(artList));

    }

    @Test
    public void testfab() {
        Fab fab = new Fab();
        fab.setArtTitle("我的第一");
        fab.setUserAccount("lyh321");

        int f = fabService.addFab(fab);
        System.out.println(f);
    }

    @Test
    public void findfab() {
        List<Fab> fabList = fabService.findAllFab();
        for (int i = 0; i < fabList.size(); i++) {

            System.out.println(fabList.get(i).getFabNumber());

        }
        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(fabList));
    }

    @Test
    public void fabupdate() {
        Fab fab = new Fab();
        fab.setArtTitle("我的第一");
        fab.setUserAccount("lyh321");
        fab.setFabNumber(1);
        int f = fabService.updateByTitleAndAccount(fab);
        System.out.println(f);
    }

    @Test
    public void forwordInsert() {
        Forword forword = new Forword();
        forword.setForwordUser("lyh");
        forword.setForwordTitle("我的博客");
        forword.setForwordContext("不知道");
        forwordService.addForword(forword);
    }

    @Test
    public void forwordFind() {

       List<Forword> forwordList = forwordService.findAllForword();
        LOGGER.info("-------->>>>>>>>>>>" + JSON.toJSON(forwordList));
    }
}
